import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import { v4 as uuid } from 'uuid'
import { setSid, getSid } from '@/utils/auth'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    sid: getSid(),
    isLogin: false,
    token: '',
    userInfo: {}
  },
  mutations: {
    setSid (state) {
      const sid = uuid()
      setSid(sid)
      state.sid = sid
    },
    setIsLogin (state, value) {
      state.isLogin = value
    },
    setToken (state, value) {
      state.token = value
    },
    // 设置用户信息
    setUserInfo (state, value) {
      state.userInfo = value
    },
    logout (state) {
      state.userInfo = {}
      state.token = ''
      state.isLogin = false
    }
  },
  actions: {},
  modules: {},
  plugins: [createPersistedState()]
})
